package com.bawei.mall.product.controller;

import com.bawei.common.core.utils.poi.ExcelUtil;
import com.bawei.common.core.web.controller.BaseController;
import com.bawei.common.core.web.domain.AjaxResult;
import com.bawei.common.core.web.page.TableDataInfo;
import com.bawei.common.log.annotation.Log;
import com.bawei.common.log.enums.BusinessType;
import com.bawei.common.security.annotation.RequiresPermissions;
import com.bawei.mall.product.domain.Advertise;
import com.bawei.mall.product.service.IAdvertiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 广告Controller
 *
 * @author DongZeLiang
 * @date 2024-07-01
 */
@RestController
@RequestMapping("/advertise")
public class AdvertiseController extends BaseController
{
    @Autowired
    private IAdvertiseService advertiseService;

    /**
     * 查询广告列表
     */
    @RequiresPermissions("product:advertise:list")
    @GetMapping("/list")
    public TableDataInfo list(Advertise advertise){
        startPage();
        List<Advertise> list = advertiseService.selectAdvertiseList(advertise);
        return getDataTable(list);
    }

    /**
     * 导出广告列表
     */
    @RequiresPermissions("product:advertise:export")
    @Log(title = "广告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Advertise advertise)
    {
        List<Advertise> list = advertiseService.selectAdvertiseList(advertise);
        ExcelUtil<Advertise> util = new ExcelUtil<Advertise>(Advertise.class);
        util.exportExcel(response, list, "广告数据");
    }

    /**
     * 获取广告详细信息
     */
    @RequiresPermissions("product:advertise:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(advertiseService.selectAdvertiseById(id));
    }

    /**
     * 新增广告
     */
    @RequiresPermissions("product:advertise:add")
    @Log(title = "广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Advertise advertise)
    {
        return toAjax(advertiseService.insertAdvertise(advertise));
    }

    /**
     * 修改广告
     */
    @RequiresPermissions("product:advertise:edit")
    @Log(title = "广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Advertise advertise)
    {
        return toAjax(advertiseService.updateAdvertise(advertise));
    }

    /**
     * 删除广告
     */
    @RequiresPermissions("product:advertise:remove")
    @Log(title = "广告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(advertiseService.deleteAdvertiseByIds(ids));
    }
}
